package com.sharedlease.check;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.sharedlease.entity.Chat;
import com.sharedlease.entity.Message;
import com.sharedlease.entity.Product;
import com.sharedlease.service.ChatService;
import com.sharedlease.service.ProductService;
import com.sharedlease.websocket.ScheduleUtil;
import org.quartz.SchedulerException;

import java.util.HashSet;
import java.util.Set;

public class ReviewUtil {

    public static void review(String info, ProductService productService, ChatService chatService, Product product, boolean isUpdate) throws InterruptedException, SchedulerException {
        boolean flag = false;
        Set<String> factory = IllegalInfoFactory.getFactory();
        for (String pattern : factory){
            if (flag) break;
            if (KmpReview.find_pattern(info, pattern) > -1) flag = true;
        }
        if (flag) {
            // 人工审核
            productService.save(product);
            System.out.println("人工审核");
        }else {
            // 通过
            // 发送消息给商家 --> 商品已通过
            product.setLegal(1);
            if (isUpdate) productService.updateById(product);
            else productService.save(product);
            String s = "审核通过";
            Chat chat = new Chat(IdWorker.getId(), 1L, "robot", product.getMid(), s, 0);
            chatService.save(chat);
            System.out.println("自动通过");
        }
    }
}
